package org.msfj.admin.org.controller;

import org.msfj.admin.model.RoleMenu;
import org.msfj.admin.vo.RoleMenuVo;
import org.msfj.admin.model.RoleMenu;
import org.msfj.admin.vo.RoleMenuVo;
import org.msfj.admin.model.RoleMenu;
import org.msfj.admin.vo.RoleMenuVo;
import org.msfj.common.context.UserContextHandler;
import org.msfj.admin.org.service.RoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统角色菜单关联信息controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:20
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统角色菜单关联信息接口", tags = "系统角色菜单关联信息接口")
@RestController
@RequestMapping("org/roleMenu")
public class RoleMenuController extends BaseController{

    @Autowired
    private RoleMenuService roleMenuService;

    /**
     * 添加系统角色菜单关联信息
     *
     * @param roleMenuVo
     * @return CommonResult.ok(RoleMenuVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统角色菜单关联信息",notes = "添加系统角色菜单关联信息")
    @ApiImplicitParam(value = "roleMenuVo",name = "roleMenuVo",dataType = "org.msfj.admin.vo.RoleMenuVo",paramType = "query")
    public CommonResult addRoleMenu(RoleMenuVo roleMenuVo){
        RoleMenu roleMenu = roleMenuService.saveOrEdit(roleMenuVo);
        return CommonResult.ok(roleMenuService.setOtherProperties(roleMenu));
    }

    /**
     * 批量添加系统角色菜单关联信息
     *
     * @param roleId
     * @param menuIds
     * @return CommonResult.ok(RoleMenuVo)
     */
    @PostMapping("/addList")
    @ResponseBody
    @ApiOperation(value = "添加系统角色菜单关联信息", notes = "添加系统角色菜单关联信息")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "roleId", name = "roleId", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(value = "menuIds", name = "menuIds", dataType = "java.util.List", paramType = "query")
    })
    public CommonResult addRoleMenu(String roleId, @RequestParam(value = "menuIds[]",required = false) List<String> menuIds) {
        roleMenuService.saveListByRoleMenu(roleId, menuIds,UserContextHandler.getUserID());
        return CommonResult.ok();
    }

    /**
     * 修改系统角色菜单关联信息
     *
     * @param roleMenuVo
     * @return CommonResult.ok(RoleMenuVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统角色菜单关联信息",notes = "修改系统角色菜单关联信息")
    @ApiImplicitParam(value = "roleMenuVo",name = "roleMenuVo",dataType = "org.msfj.admin.vo.RoleMenuVo",paramType = "query")
    public CommonResult editRoleMenu(RoleMenuVo roleMenuVo){
        RoleMenu roleMenu = roleMenuService.saveOrEdit(roleMenuVo);
        return CommonResult.ok(roleMenuService.setOtherProperties(roleMenu));
    }

    /**
     * 逻辑删除系统角色菜单关联信息
     *
     * @param roleMenuVo
     * @return CommonResult.ok(RoleMenuVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统角色菜单关联信息",notes = "逻辑删除系统角色菜单关联信息")
    @ApiImplicitParam(value = "roleMenuVo",name = "roleMenuVo",dataType = "org.msfj.admin.vo.RoleMenuVo",paramType = "query")
    public CommonResult delRoleMenu(RoleMenuVo roleMenuVo){
        RoleMenu roleMenu = roleMenuService.delById(roleMenuVo);
        return CommonResult.ok(roleMenuService.setOtherProperties(roleMenu));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统角色菜单关联信息",notes = "逻辑删除系统角色菜单关联信息")
    @ApiImplicitParam(value = "ids",name = "ids",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam("ids[]") List<String> ids){
        RoleMenu roleMenu = new RoleMenu();
        roleMenuService.delByIds(ids, roleMenu);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统角色菜单关联信息
     *
     * @param roleMenuVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统角色菜单关联信息",notes = "真实删除系统角色菜单关联信息")
    @ApiImplicitParam(value = "roleMenuVo",name = "roleMenuVo",dataType = "org.msfj.admin.vo.RoleMenuVo",paramType = "query")
    public CommonResult deleteRoleMenu(RoleMenuVo roleMenuVo){
        roleMenuService.trueDelById(roleMenuVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统角色菜单关联信息
     *
     * @param roleMenuVo
     * @return CommonResult.ok(RoleMenuVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统角色菜单关联信息",notes = "根据id查找系统角色菜单关联信息")
    @ApiImplicitParam(value = "roleMenuVo",name = "roleMenuVo",dataType = "org.msfj.admin.vo.RoleMenuVo",paramType = "query")
    public CommonResult getRoleMenu(RoleMenuVo roleMenuVo){
        RoleMenu roleMenu = roleMenuService.getById(roleMenuVo.getId());
        return CommonResult.ok(roleMenuService.setOtherProperties(roleMenu));
    }

    /**
     * 根据翻页参数、搜索参数查找系统角色菜单关联信息
     *
     * @param roleMenuVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<RoleMenuVo>)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统角色菜单关联信息",notes = "根据翻页参数、搜索参数查找系统角色菜单关联信息")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "roleMenuVo",name = "roleMenuVo",dataType = "org.msfj.admin.vo.RoleMenuVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findRoleMenuList(RoleMenuVo roleMenuVo, Integer page, Integer rows){
        PageInfo<RoleMenuVo> roleMenuVoPageInfo = roleMenuService.getByRoleMenu(roleMenuVo,page,rows);
        return CommonResult.ok(roleMenuVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统角色菜单关联信息
     *
     * @param roleMenuVo
     * @return CommonResult.ok(List<RoleMenuVo>)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统角色菜单关联信息",notes = "根据搜索参数查找所有系统角色菜单关联信息")
    @ApiImplicitParam(value = "roleMenuVo",name = "roleMenuVo",dataType = "org.msfj.admin.vo.RoleMenuVo",paramType = "query")
    public CommonResult getAllRoleMenu(RoleMenuVo roleMenuVo){
        List<RoleMenuVo> roleMenuVoList = roleMenuService.getAllRoleMenu(roleMenuVo);
        return CommonResult.ok(roleMenuVoList);
    }
}
